package com.ruoyi.hatha.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hatha.domain.PJifen;
import com.ruoyi.hatha.service.IPJifenService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 我的积分Controller
 * 
 * @author Dong
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/hatha/jifen")
public class PJifenController extends BaseController
{
    @Autowired
    private IPJifenService pJifenService;

    /**
     * 查询我的积分列表
     */
    @PreAuthorize("@ss.hasPermi('hatha:jifen:list')")
    @GetMapping("/list")
    public TableDataInfo list(PJifen pJifen)
    {
        startPage();
        List<PJifen> list = pJifenService.selectPJifenList(pJifen);
        return getDataTable(list);
    }

    @GetMapping("/getjifen")
    public AjaxResult getjifen()
    {
        Long uid = SecurityUtils.getUserId();
        PJifen pj = pJifenService.getjifen(uid);
        return AjaxResult.success(pj);
    }

    @GetMapping("/getjifenlist")
    public AjaxResult getjifenlist()
    {
        Long uid = SecurityUtils.getUserId();
        PJifen pJifen = new PJifen();
        pJifen.setUid(uid);
        List<PJifen> pj = pJifenService.selectPJifenList(pJifen);
        return AjaxResult.success(pj);
    }

    /**
     * 导出我的积分列表
     */
    @PreAuthorize("@ss.hasPermi('hatha:jifen:export')")
    @Log(title = "我的积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PJifen pJifen)
    {
        List<PJifen> list = pJifenService.selectPJifenList(pJifen);
        ExcelUtil<PJifen> util = new ExcelUtil<PJifen>(PJifen.class);
        util.exportExcel(response, list, "我的积分数据");
    }

    /**
     * 获取我的积分详细信息
     */
    @PreAuthorize("@ss.hasPermi('hatha:jifen:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pJifenService.selectPJifenById(id));
    }

    /**
     * 新增我的积分
     */
    @PreAuthorize("@ss.hasPermi('hatha:jifen:add')")
    @Log(title = "我的积分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PJifen pJifen)
    {
        return toAjax(pJifenService.insertPJifen(pJifen));
    }

    /**
     * 修改我的积分
     */
    @PreAuthorize("@ss.hasPermi('hatha:jifen:edit')")
    @Log(title = "我的积分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PJifen pJifen)
    {
        return toAjax(pJifenService.updatePJifen(pJifen));
    }

    /**
     * 删除我的积分
     */
    @PreAuthorize("@ss.hasPermi('hatha:jifen:remove')")
    @Log(title = "我的积分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pJifenService.deletePJifenByIds(ids));
    }
}
